﻿using CoHubServerCore.Entity;

namespace CoHubServerCore.Security;

public class PasswordCryptor(Rsa rsa)
{
    public Password Encrypt(string password)
    {
        Aes aes = new();
        return new Password(rsa.Encrypt(aes.Key), aes.Encrypt(password));
    }

    public string? Decrypt(Password secret)
    {
        var key = rsa.Decrypt(secret.Key);
        return key != null ? new Aes(key).Decrypt(secret.Pwd) : null;
    }
}